<?php


namespace app\adminapi\validate\member;


use app\common\model\member\MemberBenefit;
use app\common\model\member\MemberLevel;
use app\common\validate\BaseValidate;

/**
 * @projectName src
 */
class MemberBenefitValidate extends BaseValidate
{
    protected $rule = [
        'id' => 'require|checkMemberBenefit',
        'level_id'=>'require|checkMemberLevel',
        'benefit_name' => 'require'
    ];

    protected $message = [
        'id.require' => '参数缺失',
        'level_id.require' => '请填写会员等级',
        'benefit_name.require' => '请填写权益名称',
    ];

    /**
     * @notes 添加场景
     * sceneAdd
     */
    public function sceneAdd()
    {
        return $this->remove('id', true);
    }

    /**
     * @notes 详情场景
     * sceneAdd
     */
    public function sceneDetail()
    {
        return $this->only(['id']);
    }

    /**
     * @notes 编辑场景
     * sceneAdd
     */
    public function sceneEdit()
    {
    }

    /**
     * @notes 删除场景
     * sceneAdd
     */
    public function sceneDelete()
    {
        return $this->only(['id']);
    }

    public function checkMemberBenefit($value)
    {
        $memberBenefit = MemberBenefit::findOrEmpty($value);
        if ($memberBenefit->isEmpty()) {
            return '会员等级权益不存在';
        }
        return true;
    }

    public function checkMemberLevel($value)
    {
        $memberLevel = MemberLevel::findOrEmpty($value);
        if ($memberLevel->isEmpty()) {
            return '会员等级不存在';
        }
        return true;
    }
}